import eventBus from '../../../eventBus';

// components/my-cartDetail/my-cartDetailMessage/my-cartDetailMessage.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    detail:[],
    detailStatus:'none',
    wrapStatus:'nowrap',
    detailTotalPrice:0,
    detailLengthStatus:'block',
    detailLength:0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    changeWrapStatus(){
        this.setData({
          wrapStatus:'wrap',
          detailLengthStatus:'none'
        })
      }
  },
  lifetimes:{
    attached(){
      eventBus.on('detailTransmit',(data)=>{
        // 整体是否显示出来
        if(this.data.detailStatus==='none'){
          this.setData({
            detailStatus:'block'
          })
        }else{
          this.setData({
            detailStatus:'none'
          })
        }
        console.log('detailTransmit,启动！');
        var packagea=JSON.parse(data)
        this.setData({
          detail:packagea,
          detailLength:packagea.length
        })
        // 控制是否显示下拉框
        if(this.data.detailLength>3){
          this.setData({
            wrapStatus:'nowrap',
            detailLengthStatus:'block'
          })
        }else{
          this.setData({
            detailLengthStatus:'none'
          })
        }
        console.log('mingxi');
        console.log(this.data.detail);
      }),
      eventBus.on('totalPriceTransmit',(data)=>{
        this.setData({
          detailTotalPrice:data
        })
      })
    },
    detached(){
      eventBus.off('detailTransmit')
      eventBus.off('totalPriceTransmit')
    }
  }
})
